package cn.edu.huanghuai.newsofhuanghuai.Controller;

import cn.edu.huanghuai.newsofhuanghuai.common.Result;
import cn.edu.huanghuai.newsofhuanghuai.sevice.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 管理员控制类
 *
 * @author whisper
 * @since 2025/06/11 21:39
 **/


@RestController
@RequestMapping("/admin")
@CrossOrigin
public class AdminController {
    @Autowired
    private  AdminService adminService;

    @GetMapping("/queryAll")
    public Result queryAll() {
        return new Result(200, "查询成功", adminService.queryAllUser());
    }

    @GetMapping("/banUser/{uid}")
    public Result banUser (@PathVariable("uid") Integer uid) {
        if (uid == null) {
            return new Result(400, "用户 ID 不能为空");
        }
        int result = adminService.banUser(uid); // 此时 uid 不为 null
        if (result > 0) {
            return new Result(200, "封禁成功");
        } else {
            return new Result(403, "封禁失败");
        }
    }

    @GetMapping("/releaseUser/{uid}")
    public Result releaseUser(@PathVariable  ("uid") Integer uid) {
        int result = adminService.releaseUser(uid);
        if(result > 0 ) {
            return new Result(200, "解封成功");
        } else {
            return new Result(403, "解封失败");
        }
    }
}
